﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using ATA.Entities;
using ATA.Data;

#endregion

namespace ATA.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwGetAllDoanhSoProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwGetAllDoanhSoProviderBaseCore : EntityViewProviderBase<VwGetAllDoanhSo>
	{
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwGetAllDoanhSo&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwGetAllDoanhSo&gt;"/></returns>
		protected static VList&lt;VwGetAllDoanhSo&gt; Fill(DataSet dataSet, VList<VwGetAllDoanhSo> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwGetAllDoanhSo>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwGetAllDoanhSo&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwGetAllDoanhSo>"/></returns>
		protected static VList&lt;VwGetAllDoanhSo&gt; Fill(DataTable dataTable, VList<VwGetAllDoanhSo> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwGetAllDoanhSo c = new VwGetAllDoanhSo();
					c.AccountingObjectId = (Convert.IsDBNull(row["AccountingObjectID"]))?Guid.Empty:(System.Guid)row["AccountingObjectID"];
					c.MaHang = (Convert.IsDBNull(row["MaHang"]))?string.Empty:(System.String)row["MaHang"];
					c.PhanLoaiHang = (Convert.IsDBNull(row["PhanLoaiHang"]))?string.Empty:(System.String)row["PhanLoaiHang"];
					c.TenHang = (Convert.IsDBNull(row["TenHang"]))?string.Empty:(System.String)row["TenHang"];
					c.DonVi = (Convert.IsDBNull(row["DonVi"]))?string.Empty:(System.String)row["DonVi"];
					c.DoanhSoTrongThang = (Convert.IsDBNull(row["DoanhSoTrongThang"]))?0:(System.Decimal?)row["DoanhSoTrongThang"];
					c.SoLuong = (Convert.IsDBNull(row["SoLuong"]))?0.0m:(System.Decimal?)row["SoLuong"];
					c.SoHoaDon = (Convert.IsDBNull(row["SoHoaDon"]))?string.Empty:(System.String)row["SoHoaDon"];
					c.NgayHoaDon = (Convert.IsDBNull(row["NgayHoaDon"]))?DateTime.MinValue:(System.DateTime)row["NgayHoaDon"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwGetAllDoanhSo&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwGetAllDoanhSo&gt;"/></returns>
		protected VList<VwGetAllDoanhSo> Fill(IDataReader reader, VList<VwGetAllDoanhSo> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwGetAllDoanhSo entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwGetAllDoanhSo>("VwGetAllDoanhSo",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwGetAllDoanhSo();
					}
					entity.AccountingObjectId = (System.Guid)reader["AccountingObjectID"];
					//entity.AccountingObjectId = (Convert.IsDBNull(reader["AccountingObjectID"]))?Guid.Empty:(System.Guid)reader["AccountingObjectID"];
					entity.MaHang = (System.String)reader["MaHang"];
					//entity.MaHang = (Convert.IsDBNull(reader["MaHang"]))?string.Empty:(System.String)reader["MaHang"];
					entity.PhanLoaiHang = (System.String)reader["PhanLoaiHang"];
					//entity.PhanLoaiHang = (Convert.IsDBNull(reader["PhanLoaiHang"]))?string.Empty:(System.String)reader["PhanLoaiHang"];
					entity.TenHang = (System.String)reader["TenHang"];
					//entity.TenHang = (Convert.IsDBNull(reader["TenHang"]))?string.Empty:(System.String)reader["TenHang"];
					entity.DonVi = reader.IsDBNull(reader.GetOrdinal("DonVi")) ? null : (System.String)reader["DonVi"];
					//entity.DonVi = (Convert.IsDBNull(reader["DonVi"]))?string.Empty:(System.String)reader["DonVi"];
					entity.DoanhSoTrongThang = reader.IsDBNull(reader.GetOrdinal("DoanhSoTrongThang")) ? null : (System.Decimal?)reader["DoanhSoTrongThang"];
					//entity.DoanhSoTrongThang = (Convert.IsDBNull(reader["DoanhSoTrongThang"]))?0:(System.Decimal?)reader["DoanhSoTrongThang"];
					entity.SoLuong = reader.IsDBNull(reader.GetOrdinal("SoLuong")) ? null : (System.Decimal?)reader["SoLuong"];
					//entity.SoLuong = (Convert.IsDBNull(reader["SoLuong"]))?0.0m:(System.Decimal?)reader["SoLuong"];
					entity.SoHoaDon = (System.String)reader["SoHoaDon"];
					//entity.SoHoaDon = (Convert.IsDBNull(reader["SoHoaDon"]))?string.Empty:(System.String)reader["SoHoaDon"];
					entity.NgayHoaDon = (System.DateTime)reader["NgayHoaDon"];
					//entity.NgayHoaDon = (Convert.IsDBNull(reader["NgayHoaDon"]))?DateTime.MinValue:(System.DateTime)reader["NgayHoaDon"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwGetAllDoanhSo"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwGetAllDoanhSo"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwGetAllDoanhSo entity)
		{
			reader.Read();
			entity.AccountingObjectId = (System.Guid)reader["AccountingObjectID"];
			//entity.AccountingObjectId = (Convert.IsDBNull(reader["AccountingObjectID"]))?Guid.Empty:(System.Guid)reader["AccountingObjectID"];
			entity.MaHang = (System.String)reader["MaHang"];
			//entity.MaHang = (Convert.IsDBNull(reader["MaHang"]))?string.Empty:(System.String)reader["MaHang"];
			entity.PhanLoaiHang = (System.String)reader["PhanLoaiHang"];
			//entity.PhanLoaiHang = (Convert.IsDBNull(reader["PhanLoaiHang"]))?string.Empty:(System.String)reader["PhanLoaiHang"];
			entity.TenHang = (System.String)reader["TenHang"];
			//entity.TenHang = (Convert.IsDBNull(reader["TenHang"]))?string.Empty:(System.String)reader["TenHang"];
			entity.DonVi = reader.IsDBNull(reader.GetOrdinal("DonVi")) ? null : (System.String)reader["DonVi"];
			//entity.DonVi = (Convert.IsDBNull(reader["DonVi"]))?string.Empty:(System.String)reader["DonVi"];
			entity.DoanhSoTrongThang = reader.IsDBNull(reader.GetOrdinal("DoanhSoTrongThang")) ? null : (System.Decimal?)reader["DoanhSoTrongThang"];
			//entity.DoanhSoTrongThang = (Convert.IsDBNull(reader["DoanhSoTrongThang"]))?0:(System.Decimal?)reader["DoanhSoTrongThang"];
			entity.SoLuong = reader.IsDBNull(reader.GetOrdinal("SoLuong")) ? null : (System.Decimal?)reader["SoLuong"];
			//entity.SoLuong = (Convert.IsDBNull(reader["SoLuong"]))?0.0m:(System.Decimal?)reader["SoLuong"];
			entity.SoHoaDon = (System.String)reader["SoHoaDon"];
			//entity.SoHoaDon = (Convert.IsDBNull(reader["SoHoaDon"]))?string.Empty:(System.String)reader["SoHoaDon"];
			entity.NgayHoaDon = (System.DateTime)reader["NgayHoaDon"];
			//entity.NgayHoaDon = (Convert.IsDBNull(reader["NgayHoaDon"]))?DateTime.MinValue:(System.DateTime)reader["NgayHoaDon"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwGetAllDoanhSo"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwGetAllDoanhSo"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwGetAllDoanhSo entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.AccountingObjectId = (Convert.IsDBNull(dataRow["AccountingObjectID"]))?Guid.Empty:(System.Guid)dataRow["AccountingObjectID"];
			entity.MaHang = (Convert.IsDBNull(dataRow["MaHang"]))?string.Empty:(System.String)dataRow["MaHang"];
			entity.PhanLoaiHang = (Convert.IsDBNull(dataRow["PhanLoaiHang"]))?string.Empty:(System.String)dataRow["PhanLoaiHang"];
			entity.TenHang = (Convert.IsDBNull(dataRow["TenHang"]))?string.Empty:(System.String)dataRow["TenHang"];
			entity.DonVi = (Convert.IsDBNull(dataRow["DonVi"]))?string.Empty:(System.String)dataRow["DonVi"];
			entity.DoanhSoTrongThang = (Convert.IsDBNull(dataRow["DoanhSoTrongThang"]))?0:(System.Decimal?)dataRow["DoanhSoTrongThang"];
			entity.SoLuong = (Convert.IsDBNull(dataRow["SoLuong"]))?0.0m:(System.Decimal?)dataRow["SoLuong"];
			entity.SoHoaDon = (Convert.IsDBNull(dataRow["SoHoaDon"]))?string.Empty:(System.String)dataRow["SoHoaDon"];
			entity.NgayHoaDon = (Convert.IsDBNull(dataRow["NgayHoaDon"]))?DateTime.MinValue:(System.DateTime)dataRow["NgayHoaDon"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwGetAllDoanhSoFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwGetAllDoanhSo"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwGetAllDoanhSoFilterBuilder : SqlFilterBuilder<VwGetAllDoanhSoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoFilterBuilder class.
		/// </summary>
		public VwGetAllDoanhSoFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwGetAllDoanhSoFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwGetAllDoanhSoFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwGetAllDoanhSoFilterBuilder

	#region VwGetAllDoanhSoParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwGetAllDoanhSo"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwGetAllDoanhSoParameterBuilder : ParameterizedSqlFilterBuilder<VwGetAllDoanhSoColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoParameterBuilder class.
		/// </summary>
		public VwGetAllDoanhSoParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwGetAllDoanhSoParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwGetAllDoanhSoParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwGetAllDoanhSoParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwGetAllDoanhSoParameterBuilder
} // end namespace
